#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>

static int g_count = 0;
static int g_obj_sig = 0;

void signal_handler(int sig, siginfo_t* info, void* ucontext)
{
    if (sig == g_obj_sig) {
        g_count++;
    }
}

int main(int argc, char* argv[])
{
    struct sigaction act = {0};
    sigset_t set = {0};
    int i = 0;
    
    g_obj_sig = atoi(argv[1]);
    printf("current pid(%d) ...\n", getpid());

    act.sa_sigaction = signal_handler;
    act.sa_flags = SA_SIGINFO;
    
    sigaddset(&act.sa_mask, g_obj_sig);
    
    sigaction(g_obj_sig, &act, NULL);

    sigfillset(&set);
    sigprocmask(SIG_SETMASK, &set, NULL);

    for (i = 0; i < 15; i++) {
        sleep(1);
        printf("i = %d\n", i);
    }

    sigemptyset(&set);
    sigprocmask(SIG_SETMASK, &set, NULL);

    printf("g_count = %d\n", g_count);

    return 0;
}

